﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LTJ.Common;
using LTJ.Entity;
using LTJ.FrameWork;
using System.Data;

namespace uswinweb.admin
{
    public partial class usermanage_update : AdminPage
    {
        public UserInfo uInfo = new UserInfo();
        public int uid = SASRequest.GetInt("uid", 0);
        public DataTable ugTab = new DataTable();
        public string keyword = LTJ.Common.Utils.UrlDecode(SASRequest.GetString("parms").Trim());
        protected void Page_Load(object sender, EventArgs e)
        {
            ugTab = UserGroup.GetUserGroupList("");
            if (uid != 0)
            {
                uInfo = Users.GetUser(uid);
            }
            if (SASRequest.IsPost())
            {
                UpdateUser();
            }

        }
        protected void UpdateUser()
        {
            
            string lname = SASRequest.GetFormString("uLnametxt");
            string ename = SASRequest.GetFormString("uEnametxt");
            int gid = SASRequest.GetFormInt("group_hidd_luffy", 0);
            int cid = SASRequest.GetFormInt("comp_hidd_luffy", 0);
            int status = SASRequest.GetFormInt("status_radio", 0);
            string authority = "";
            if (SASRequest.GetString("authority1") != "")
            {
                authority += SASRequest.GetString("authority1") + ",";
            }
            if (SASRequest.GetString("authority2") != "")
            {
                authority += SASRequest.GetString("authority2") + ",";
            }
            if (SASRequest.GetString("authority3") != "")
            {
                authority += SASRequest.GetString("authority3") + ",";
            }
            uInfo.cid = cid;
            uInfo.gid = gid;
            uInfo.rname = lname;
            uInfo.ename = ename;
            uInfo.status = status;
            uInfo.authority = authority.Trim(',');
           bool msg= Users.UpdateUser(uInfo);
           if (msg == true)
           {
               base.RegisterStartupScript("PAGE", "parent.document.getElementById('reclick').click();parent.Lightview.hide();");
           }
           else
           {
               base.RegisterStartupScript("PAGETEMPLATE", "更新失败!");
           }
        }
        public string GetGroupName(int id)
        {
            string msg = "";
            UserGroupInfo ugInfo = UserGroup.GetUserGroupInfo(id);
            if (ugInfo != null)
            {
                msg = ugInfo.name;
            }
            return msg;
        }
        public string GetCompName(int id)
        {
            string msg = "";
            CompanyInfo compInfo = Companys.GetCompanyByID(id);
            if (compInfo != null)
            {
                msg = compInfo.cname;
            }
            return msg;
        }
    }
}